﻿//======================================================================
//
//        Copyright (C) 2015   
//        All rights reserved
//
//        filename : ReturnCard
//        description : 卡片退货
//        created by XXX at  20150821
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;

namespace CardLogistics.Web.MainPage.CardRecovery.ReturnCard
{
    public partial class Detail : BasePage
    {
        private static readonly CardLogistics.DAL.CardRecovery.CARDRECOVERY_RETURNCARDData DAL = new DAL.CardRecovery.CARDRECOVERY_RETURNCARDData();
        private static readonly CardLogistics.DAL.CardRecovery.CARDRECOVERY_RETURNCARD_DETAILData DDAL = new DAL.CardRecovery.CARDRECOVERY_RETURNCARD_DETAILData();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void InitControl()
        {
            string _key = Request.QueryString["id"];
            WebUserControl_AppInfo1.InfoID = _key;
            WebUserControl_AppInfo1.UserID = LoggedUser.ID;
            if (!string.IsNullOrEmpty(_key))
            {
                CardLogistics.Model.CardRecovery.CARDRECOVERY_RETURNCARD rData = DAL.GetModel(_key);
                SetWebControls(this.Page, rData);
                if (rData!= null)
                {
                    //申请日期
                    if (rData.RETURNDATA != null)
                    {
                        RETURNDATA.Text = DateTime.Parse(rData.RETURNDATA.ToString()).ToString("yyyy-MM-dd");
                    }
                    GetConDetInfo(rData.CONID);//根据合同ID获取合同明细
                    DataTable dt = DDAL.GetInfoByReturnId(rData.ID);//查询卡片退货单明细信息
                    rptDetailList.DataSource = dt;
                    rptDetailList.DataBind();
                }
            }
        }
        /// <summary>
        /// 根据合同ID获取合同明细
        /// </summary>
        /// <param name="conId">合同明细ID</param>
        private void GetConDetInfo(string conId)
        {
            DataTable dt = new DAL.Purchase.Purchase_Contract_detailData().GetInfoById(conId);
            if (dt.Rows.Count > 0)
            {
                lblConInfo.Text = "供应商:" + dt.Rows[0]["suppliersname"].ToString();
                lblConInfo.Text += " 芯片类型:" + dt.Rows[0]["typename"].ToString();
                lblConInfo.Text += " 单价:" + decimal.Parse(dt.Rows[0]["PRICE"].ToString()).ToString("0.00") + "元/张";
                lblConInfo.Text += " 数量:" + dt.Rows[0]["CARDAMOUNT"].ToString() + "张";
                lblConInfo.Text += " 备品数量:" + dt.Rows[0]["SPAREPARTS"].ToString() + "张";
                lblConInfo.Text += " 赠品数量:" + dt.Rows[0]["PREMIUMS"].ToString() + "张";
                lblConInfo.Text += " 数量合计:" + dt.Rows[0]["allTotal"].ToString() + "张";
                lblConInfo.Text += " 金额合计:" + (decimal.Parse(dt.Rows[0]["PRICE"].ToString()) * decimal.Parse(dt.Rows[0]["CARDAMOUNT"].ToString())).ToString("0.00") + "元";
                PConNo.Text = dt.Rows[0]["Conno"].ToString();//合同编号赋值
            }
        }
    }
}